const moment = require('moment')

//@SpringBoot
class Application {

	//@Autowired
	coinInvestService;

	//@Autowired
	systemLogService;

	//@Autowired
	lifeCircleService;

	//@Autowired
	unifyOrderService;

	//@Autowired
	marketSentimentService;

	async main(){

		//更新市场情绪数据
		await this.marketSentimentService.autoUpdate();

		//获取购买间隔
		const buyInterval = this.coinInvestService.getByInterval();

		//心跳方法 周期一分钟
		setInterval(async ()=>{

			try{

				//距离上次下单时间需大于购买间隔
				if(moment().valueOf() - this.lifeCircleService.getLastOrderTime() > buyInterval){

					//统一下单
					await this.unifyOrderService.doUnifyOrder();

				}

			}catch(e){
				try{
					console.log(e)
					await this.systemLogService.operateError(`系统出现错误:${e}`,true);
				}catch(e){
					console.log("异常处理错误",e);
				}

			}

		},this.coinInvestService.hearbeat*1000)

		//记录系统启动
		this.lifeCircleService.startInfo(buyInterval);

	}

}

 module.exports = { Application }